import Vue from 'vue'
import VueRouter from 'vue-router'

import Home from 'views/home/home'
import Index from 'views/home/index'
import Classify from 'views/home/classify'
import Profile from 'views/home/profile'
import Cart from 'views/home/cart'
import Search from 'components/Search.vue'
import Longin from 'views/Login.vue'
import Register from 'views/Register.vue'
import Set from 'views/Set.vue'
import Indent from 'views/indent.vue'
import MsEntry from 'views/MsEntry.vue'
import Particulars from 'components/Particulars.vue'
import ClassfiyList from 'components/Classfiylist'
import CartList from 'views/CartList'

Vue.use(VueRouter)
const routes = [{
        path: '/',
        redirect: '/home'

    },
    {
        path: '/home',
        redirect: '/home/index',
        component: Home,
        children: [{
                path: 'index',
                name: 'index',
                component: Index,
                meta: {
                    path: '/home/index',
                    num: 0
                },
            },
            {
                path: 'classify',
                name: 'classify',
                meta: {
                    path: '/home/classify',
                    num: 1
                },
                component: Classify,
            },
           
            {
                path: 'Login',
                name: 'login',
                component: Longin
            },
            {
                path: 'cart',
                name: 'cart',
                component: Cart,
                meta: {
                    path: '/home/cart',
                    num: 2
                }
            },
            {
                path: 'profile',
                name: 'profile',
                meta: {
                    path: '/home/profile',
                    num: 3
                },
                component: Profile
            },

        ]
    },
    {
        path: '/Longin',
        name: 'Longin',
        component: Longin
    },
    {
        path: '/search',
        name: 'Search',
        component: Search
    },
    {
        path: '/Register',
        name: 'register',
        component: Register
    },
    {
        path: '/Set',
        component: Set
    },
    {
        path: '/Indent',
        component: Indent
    },
    {
        path: '/MsEntry/:id',
        component: MsEntry

    },
    {
        path: '/Particulars/:id',
        name:'Particulars',
        component: Particulars
    }, {
        path: '/Indent',
        component: Indent
    },
    {
        path: '/cartlist',
        component: CartList
    },

    {
        path:'/Classfiylist/:id',
        name:'Classfiylist',
        meta: {
            path: '/Classfiylist'
        },
        component:ClassfiyList
    },
]


const routers = new VueRouter({
    routes,
    mode: 'history'
})
routers.beforeEach(async(to,from,next)=>{
    if(to.path == '/Longin'){
        next()
        return
    }
    let res = await userAuth()
    if(res.data.code == 1){
        next()
    }else{
        next('/Longin')
    }
})

export default routers